package top.yehot.kettle.boot.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import top.yehot.cmm.util.core.base.Result;
import top.yehot.cmm.util.spring.anns.ResponseResult;
import top.yehot.kettle.boot.core.SysConst;
import top.yehot.kettle.boot.models.vo.directory.DirectoryAddVO;
import top.yehot.kettle.boot.models.vo.directory.DirectoryEditVO;
import top.yehot.kettle.boot.models.vo.directory.DirectoryVO;
import top.yehot.kettle.boot.service.DirectoryService;

/**
 * 资源库树管理
 * 
 * @author lquan
 * @date 2022年6月1日 上午12:40:25
 */
@Api(tags = "资源库树管理")
@RestController
@RequestMapping(SysConst.VERSION + "/dicategory")
@AllArgsConstructor
@ResponseResult
public class DirectoryController {
	
	private final DirectoryService directoryService;

	@ApiOperation("查询资源库目录树")
    @GetMapping("findTree")
    public List<DirectoryVO> findTree(@RequestParam("repoId") String repoId, @RequestParam(value = "pid", required = false) String pid) {
		return directoryService.findTree(repoId, pid);
	}
	
	@ApiOperation("创建目录")
	@PostMapping("createDir")
	public Result<?> createDir(@RequestBody @Valid DirectoryAddVO param) {
		return directoryService.createDir(param);
	}
	
	@ApiOperation("重命名目录")
	@PostMapping("modifyDir")
	public Result<?> modifyDir(@RequestBody @Valid DirectoryEditVO param) {
		return directoryService.modifyDir(param);
	}
	
	@ApiOperation("删除目录")
	@GetMapping("deleteDir")
	public Result<?> deleteDir(@RequestParam("repId") String repId, @RequestParam("dirId") String dirId) {
		return directoryService.deleteDir(repId, dirId);
	}
	
}
